package com.abocode.aichat.server.modules.handler;

import com.abocode.aichat.data.*;
import com.abocode.aichat.server.context.channel.ChannelWrapper;
import com.abocode.aichat.server.context.ServerRuntimeContext;
import com.abocode.aichat.server.modules.ModuleServiceHandler;
import com.abocode.aichat.server.context.delivery.reply.Replies;
import com.alibaba.fastjson.JSON;

/**
 * @author guanxf
 */
public class ChatOfflineServiceHandler implements ModuleServiceHandler {
    @Override
    public Replies execute(ChannelWrapper channelWrapper, MessageStanza stanza, ServerRuntimeContext serverRuntimeContext) {
        ReqMessageBody body = JSON.parseObject(stanza.body().toString(),ReqMessageBody.class);
        String jid =body.getJid();
        Entity jidEntity = EntityImpl.parse(jid);
        return serverRuntimeContext.getMessagePipeline().messages(channelWrapper.getChannel(),jidEntity);
    }

    @Override
    public ModuleServiceType moduleServiceType() {
        return ModuleServiceType.offline;
    }
}
